package cn.yudao.ymcc.Listener;

import cn.yudao.ymcc.domain.MessageBlacklist;
import cn.yudao.ymcc.mapper.MessageBlacklistMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.EventListener;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.util.List;

@Component
public class BlacklistListener implements ApplicationListener {

    @Autowired
    private MessageBlacklistMapper blacklistMapper;

    @Autowired
    private RedisTemplate<Object,Object> redisTemplate;


    /**
    * @Title: onApplicationEvent
    * @Description: 使用监听器当项目一启动的时候就把数据放到redis中
    * @Author: Mr.Jia
    * @Version: 1.0
    * @Date:  2022/8/8 15:59
    * @Parameters:
    * @Return
    */
    @Override
    public void onApplicationEvent(ApplicationEvent applicationEvent) {
        // 放到redis中的操作
//        List<MessageBlacklist> list = blacklistMapper.selectList(null);
//        redisTemplate.opsForValue().set("black",list);
//        for (MessageBlacklist black : list) {
//            redisTemplate.opsForValue().set(black.getId().toString(),black);
//            redisTemplate.opsForValue().set(black.getPhone(),black);
//        }
    }
}
